package banwood.com.xiongfasy.activity;


import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


import com.google.gson.Gson;

import banwood.com.xiongfasy.BASE.BaseActivity;
import banwood.com.xiongfasy.R;
import banwood.com.xiongfasy.bean.BillDetail;
import banwood.com.xiongfasy.dialog.LoadingDialog;
import banwood.com.xiongfasy.http.GetAsynctask;
import banwood.com.xiongfasy.listener.ResultListener;
import banwood.com.xiongfasy.utils.LogUtils;
import butterknife.BindView;
import cn.shellinfo.serv.comm.ParamMap;

/*
 * 
 * 查询页面
 * */
public class InquiryActivity extends BaseActivity {

    private static String TAG="InquiryActivity";

    @BindView(R.id.tuikuai_hao)
    EditText tuikuaiHao;
    @BindView(R.id.tuikuai_start)
    Button tuikuaiStart;
    private LoadingDialog dialog;

    @Override
    protected int getLayoutId() {
        return R.layout.tuikuai_xml;
    }

    @Override
    protected void initView() {
        settitle("查询交易流水");
        tuikuaiStart.setText("提交");
        tuikuaiStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(!TextUtils.isEmpty(tuikuaiHao.getText().toString().trim())){
                    startQuery(tuikuaiHao.getText().toString());
                    tuikuaiHao.setText("");
                }else{
                    Toast.makeText(InquiryActivity.this,"请输入流水号",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void startQuery(String msg) {
        dialog=new LoadingDialog(InquiryActivity.this,1);
        dialog.setMessage("正在查询信息...'");
        dialog.show();

        ParamMap paramMap=new ParamMap();
        paramMap.put("PayTypeID","ImmediatePay");
//        paramMap.put("OrderNo","ON1495697307859");
        paramMap.put("OrderNo",msg);
        paramMap.put("QueryDetail","1");

        new GetAsynctask(new ResultListener() {
            @Override
            public void getResult(ParamMap result) {
                dialog.dismiss();

                if(result!=null && result.getString("ReturnCode").equals("0000")){
                    LogUtils.d(TAG,result.toString());
                    String odrenInfo=result.getString("orderDetail");
                    Gson gson=new Gson();
                    BillDetail info=new BillDetail();
                     info=gson.fromJson(odrenInfo,BillDetail.class);
                    Intent intent=new Intent(InquiryActivity.this,BillDetailActivity.class);
                    intent.putExtra("title","查询结果");
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("param",info);
                    intent.putExtras(bundle);
                    startActivity(intent);


                }else{
                    Intent intent=new Intent(InquiryActivity.this,QueryFailActivity.class);
                    startActivity(intent);
                }


            }
        },InquiryActivity.this,paramMap,"getQueryOrder").execute(paramMap);


    }

    @Override
    protected void initData() {

    }



}
